<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%     
	String path = request.getContextPath();     
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";     
%>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>配置角色权限</title>
    <base href="<%=basePath%>"/>
    <link rel="stylesheet" href="js/ztree/css/zTreeStyle.css" type="text/css">
	<script src="js/jquery-1.8.3.min.js" type="text/javascript"></script> 
	<script src="js/ztree/js/jquery.ztree.all-3.5.min.js" type="text/javascript"></script> 
    <style type="text/css">

    </style> 	
    <script type="text/javascript">
    	<!--
    	var setting = {
    		check: {
    			enable: true
    		},
    		data: {
    			simpleData: {
    				enable: true
    			}
    		}
    	};
    
    	var zNodes =[
			<c:forEach var="node" items="${nodes}" varStatus="status">
				{ id:'${node.id}', pId:'${node.pId}', open:${node.isExpand}, enName:"${node.enName}", name:"${node.text}", isParent:${node.isParent}, checked:${node.isChecked}}
				<c:if test="${status.last == false}">,</c:if>
			</c:forEach>  
    	];    
    	
		$(document).ready(function(){
			$.fn.zTree.init($("#ztree"), setting, zNodes);
			$.ajaxSetup ({ cache:false });
		});    	

		function btn_submit() {
			var treeObj = $.fn.zTree.getZTreeObj("ztree");
			var nodes = treeObj.getCheckedNodes(true);
            var array = new Array();
            for (var i = 0; i < nodes.length; i++) {
            	if(nodes[i].isParent == 1) continue;
                array.push(nodes[i].enName);
            }

            var actions = array.join(";");
            var enname = "${enname}";
                       
            $.post("system/role/action.do", {actions:actions, enname:enname}, function(result){
            	var re = $.parseJSON(result);
            	if(re.code != 1) alert(re.msg);
            	else window.location.href="<%=basePath%>system/role/list.do?" + $("#qs").val();
            });            
		}
		//-->
    </script>    
  </head>
  
  <body>
    <div>
      <input id="qs" name="qs" type="hidden" value="${qs}"/>
      <input id="btn_submit" type="button" value="提交" onclick="btn_submit();" style="width: 80px;" />
      <input id="btn_back" type="button" value="返回" onclick="history.back();" style="width: 80px;" />
    </div>   
    <h3>${enname} 配置操作：</h3>
	<div>
		<ul id="ztree" class="ztree"></ul>
	</div>
  </body>
</html>